home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
001-025
/
scopedisk1
/
getopt
/
getopt.doc
next >
Wrap
Text File
|
1995-03-18
|
2KB
|
52 lines
GETOPT
NAME
getopt - Get next option letter from argument vector.
USAGE
int getopt(argc, argv, optstring);
#include "getopt.h"
int argc;
char *argv[], *optstring;
extern char *optarg;
extern int optind, opterr, optopt;
DESCRIPTION
The function getopt() returns the next option letter in argv that
matches a letter in optstring. Optstring is a string of valid option
letters; if an option letter is followed by a colon (:), that option
is expected to have an argument that may or may not be separated from
it by white space. Optarg is set to point to the start of the option's
argument on return from getopt();
getopt() places in optind the argv index of the next argument to be
parsed. Optind is external, and is initialized to 1 before the first
call to getopt().
When all options have been parsed (that is, up to the first non-
option argument), getopt returns EOF. The special option double dash
(--) may be used to delimit the end of the options. EOF will be
returned and the double dash will be skipped. The special option single
dash (-) may be used to indicate that stdin should be used as the next
input stream. EOF will be returned but the single dash will not be skipped.
The calling routine must then act on the presence of the single dash in the
argument vector.
DIAGNOSTICS
If the external variable opterr is non-zero (the default) getopt()
prints an error message on stderr and returns a question mark (?) when
it encounters either an option character not in optstring or a valid
option without its required argument.
In those cases where getopt() finds an option character not in
optstring, and returns a question mark, the external variable optopt
will contain the actual character found.